package com.mlethe.library.imagepreview.demo.custom;

import android.os.Bundle;

import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.mlethe.library.imagepreview.GPreviewActivity;
import com.mlethe.library.imagepreview.demo.ImageUrlConfig;
import com.mlethe.library.imagepreview.demo.R;
import com.mlethe.library.imagepreview.demo.bean.UserViewInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by yangc on 2017/9/19.
 * E-Mail:yangchaojiang@outlook.com
 * Deprecated:
 */

public class CustomActivity extends GPreviewActivity {

    private Toolbar mToolbar;

    private AppCompatButton mTestBtn;

    /***
     * 重复该方法
     * 使用你的自定义布局
     ***/
    @Override
    public View getView() {
        return getLayoutInflater().inflate(R.layout.activity_custom_preview, null, false);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mToolbar = findViewById(R.id.toolbar);
        mTestBtn = findViewById(R.id.testBtn);
        findViewById(R.id.testBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("sss","'toolbar'");
                Toast.makeText(getApplicationContext(),"测试",Toast.LENGTH_SHORT).show();
                //退出时调用，d封装方法的 不然没有动画效果
                transformOut();
            }
        });
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("sss","'toolbar'");
                //退出时调用，d封装方法的 不然没有动画效果
                transformOut();
            }
        });
        getViewPager().postDelayed(new Runnable() {
            @Override
            public void run() {
                setData();
            }
        }, 1000L);
    }

    @Override
    public void onEnterAnimationEnd() {
        super.onEnterAnimationEnd();
        mToolbar.setVisibility(View.VISIBLE);
        mTestBtn.setVisibility(View.VISIBLE);
    }

    @Override
    public void onFinishAnimationStart() {
        super.onFinishAnimationStart();
        mToolbar.setVisibility(View.INVISIBLE);
        mTestBtn.setVisibility(View.GONE);
    }

    private void setData() {
        List<UserViewInfo> list = new ArrayList<>();
        //准备数据
        List<String> urls = ImageUrlConfig.getUrls();
        for (int i = 0; i < urls.size(); i++) {
            list.add(new UserViewInfo(urls.get(i)));
        }
        setImgUrls(list);
    }
}
